import 'package:factoryside/api/api.dart';
import 'package:factoryside/bean/count_entity.dart';
import 'package:factoryside/bean/userinfo_entity.dart';
import 'package:factoryside/generated/json/count_entity_helper.dart';
import 'package:factoryside/generated/json/userinfo_entity_helper.dart';
import 'package:factoryside/home/page_login.dart';
import 'package:factoryside/utils/request_util.dart';
import 'package:factoryside/utils/utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
class Bill with ChangeNotifier{
  String dateStr;//账单时间
  String billState;//账单状态
  void changeDateStr(String dateStr,String state){
    if (this.dateStr!=dateStr||this.billState!=state) {
      this.dateStr=dateStr;
      this.billState=state;
      notifyListeners();
    }
  }
}
class User with ChangeNotifier{
  CountEntity _countEntity;
  UserinfoDataData _userInfo;

  CountEntity get countEntity => _countEntity;
  UserinfoDataData get userInfo => _userInfo;

  getUserInfo(BuildContext context,{bool getCount=true}) {
    RequestUtil.post(Api.getUserInfoList, {'UserID': Api.userName, 'limit': 1})
        .then((value) {
      if (value['StatusCode']==200) {
        _userInfo = userinfoDataDataFromJson(
            UserinfoDataData(), value['Data']['data'][0]);
        if (getCount) {
          RequestUtil.get(Api.getNewInformation, {}).then((value) {
                    _countEntity=countEntityFromJson(CountEntity(), value['Data']['data']);
                    notifyListeners();
                  });
        }else{
          notifyListeners();
        }
      }else if(value['StatusCode']==406){
        showToast('登录信息过期，请重新登录');
        ///跳转到起始页并关闭所有页面
        Navigator.pushAndRemoveUntil(
          context,
          MaterialPageRoute(builder: (context) => Login()),
              (Route<dynamic> route) => false,
        );
      }
    });
  }
}
class Head with ChangeNotifier{
  double _height;
  double get height => _height;

  set height(double value) {
    _height = value;
    notifyListeners();
  }
}